package com.teamwork.shareplatform.controller;

import com.teamwork.shareplatform.entity.Oneword;
import com.teamwork.shareplatform.service.OnewordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OnewordController {

    @Autowired
    private OnewordService onewordService;

    // 获得名人名言列表
    @GetMapping(value = "/user/oneword")
    public CommonResult<List<Oneword>> getAllQuotes() {
        CommonResult<List<Oneword>> commonResult = new CommonResult<>();
        try {
            List<Oneword> onewords = onewordService.queryAll();
            commonResult.setCode(200);
            commonResult.setMessage("获取成功");
            commonResult.setData(onewords);
        } catch (Exception e) {
            commonResult.setCode(-1);
            commonResult.setMessage("获取名人名言列表失败：" + e.getMessage());
        }
        return commonResult;
    }
}
